package hunterxhunter.greedisland.events;

import java.awt.event.KeyEvent;
import framework.eea.StateBasedGame;
import framework.eea.event.Event;
import framework.eea.gui.JFrameGameContainer;
import framework.eea.interfaces.Action;

/**
 *
 * @author Markus Schr&ouml;der
 */
public class KeyPressedEvent extends Event {

    private int[] keyCodes;
    
    public KeyPressedEvent(int... keyCodes) {
        super("KeyPressedEvent");
        this.keyCodes = keyCodes;
    }
    
    public KeyPressedEvent(Action action, int... keyCodes) {
        this(keyCodes);
        addAction(action);
    }
    
    @Override
    protected boolean performAction(JFrameGameContainer gc, StateBasedGame sb, int delta) {
        if(sb.getKeyPressedQueue().isEmpty())
            return false;
        KeyEvent e = sb.getKeyPressedQueue().peek();
        for(int keyCode : keyCodes) {
            if(e.getKeyCode() == keyCode)
                return true;
        }
        return false;
    }

}
